<template>
  <div class="count-box">
    <button @click="handleSub" class="minus">-</button>
    <input :value="modelValue" @update:modelValue="handleChange" class="inp" type="text">
    <button @click="handleAdd" class="add">+</button>
  </div>
</template>

<script setup>
const props = defineProps({
  modelValue: {
      type: Number,
      default: 1
    }
})
const emit = defineEmits(['update:modelValue'])
const handleSub = () => {
  emit('update:modelValue', props.modelValue - 1)
}
const handleChange = (e) => {
  emit('update:modelValue', e.target.value)
}
const handleAdd = () => {
  emit('update:modelValue', props.modelValue + 1)
}
</script>

<style lang="less" scoped>
.count-box {
  width: 110px;
  display: flex;
  .add, .minus {
    width: 30px;
    height: 30px;
    outline: none;
    border: none;
    background-color: #efefef;
  }
  .inp {
    width: 40px;
    height: 30px;
    outline: none;
    border: none;
    margin: 0 5px;
    background-color: #efefef;
    text-align: center;
  }
}
</style>
